import { Body, Controller, Post, Req } from '@nestjs/common';
import { CartService } from "./cart.service";
import { ApiBasicAuth, ApiExtraModels, ApiOperation, ApiTags } from "@nestjs/swagger";
import { CartAddVo } from 'src/vo/cart/cart-add.vo';
import { CartDelVo } from 'src/vo/cart/cart-del.vo';
import { ApiResult } from 'src/decorators/api-result.decorator';
import { CartEntity } from './cart.entity';
import { ResultVo } from 'src/vo/common/result.vo';
import { CartUpdateVo } from 'src/vo/cart/cart-update.vo';

@ApiExtraModels(CartEntity, ResultVo)
@Controller('cart')
@ApiTags('购物车管理')
@ApiBasicAuth("token")
export class CartController {
    constructor(private readonly cartService: CartService) { }

    @Post("queryAll")
    @ApiResult(CartEntity, true)
    @ApiOperation({ summary: '获取用户所有购物车数据' })
    async queryAll() {
        return await this.cartService.queryAll();
    }

    @Post("addCart")
    @ApiResult()
    @ApiOperation({ summary: '添加购物车商品' })
    async addCart(@Body() cartAddVo: CartAddVo) {
        return await this.cartService.addCart(cartAddVo);
    }

    @Post("updateCart")
    @ApiResult()
    @ApiOperation({ summary: '更新购物车商品' })
    async updateCart(@Body() cartUpdateVo: CartUpdateVo) {
        return await this.cartService.updateCart(cartUpdateVo);
    }

    @Post("delCart")
    @ApiResult()
    @ApiOperation({ summary: '删除购物车商品' })
    async delCart(@Body() cartDelVo: CartDelVo) {
        return await this.cartService.delCart(cartDelVo);
    }
}
